package com.shangxia.monomer.study.designPatterns.structuralType.proxy;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * @ProjectName: monomer
 * @ClassName: ProxyDemo
 * @Time: 2021/8/2
 * @Author: zhouy
 * @Description:
 * @Experience: 代理模式
 */

@Slf4j
public class ProxyDemo {
    public static void main(String[] args) {
        Gril gril = new Gril("张");
        BoyProxy boy = new BoyProxy(gril);
        boy.sendChocolate();
        boy.sendDolls();
        boy.sendFlower();
    }
}

@Data
@AllArgsConstructor
class Gril {
    private String name;
}

interface GiveGift {
    void sendFlower();

    void sendDolls();

    void sendChocolate();
}

@Data
@AllArgsConstructor
class Boy implements GiveGift {

    private Gril gril;

    @Override
    public void sendFlower() {
        System.out.println(gril.getName() + ",送你花");
    }

    @Override
    public void sendDolls() {
        System.out.println(gril.getName() + ",送你dolls");
    }

    @Override
    public void sendChocolate() {
        System.out.println(gril.getName() + ",送你巧克力");
    }
}

class BoyProxy implements GiveGift {
    private Boy boy;

    public BoyProxy(Gril gril) {
        boy = new Boy(gril);
    }

    @Override
    public void sendFlower() {
        boy.sendFlower();
    }

    @Override
    public void sendDolls() {
        boy.sendDolls();
    }

    @Override
    public void sendChocolate() {
        boy.sendChocolate();
    }
}


